(function($) {
//	$("head").append("<link>");
//	   css = $("head").children(":last");
//	   css.attr({
//	       rel: "stylesheet",
//	       type: "text/css",
//	       href: "/resource/plugins/upload/images.css"
//	});
	$.fn.imageUploadUtils = function(options, param) {
		if (typeof options == 'string') {
			return $.fn.imageUploadUtils.methods[options](this, param);
		}
		// 2.将调用时候传过来的参数和default参数合并
		options = $.extend({}, $.fn.imageUploadUtils.defaults, options || {});
		var loading = top.layer.load(0, {
			shade : [ 0.5, '#fff' ]
		}); // 0代表加载的风格，支持0-2
		$($(this).selector).on("change", function(){
			$(options.msg).html("");
			 var files = !!this.files ? this.files : [];
			 if (!files.length || !window.FileReader) 
			    return;
			 if (/^image/.test(files[0].type)){
			    	if(files[0].size>(5*1024*1024)){
			    		$(options.msg).html("图片必须在5*1024kb大小以内!");
			    		return ;
			    	}
			    	var fileExt=(/[.]/.exec(files[0].name)) ? /[^.]+$/.exec(files[0].name.toLowerCase()) : '';  
			        var reader = new FileReader();
			        var base64text = reader.readAsDataURL(files[0]);
			        reader.onloadend = function(){
			        	$(options.preview).css("background-image", "url("+this.result+")");
			      		$(options.data).val(this.result);
			      		$(options.ext).val(fileExt);
			        }
			    }else{
			    	$(options.msg).html("请选择图片!");
			    }
		});
		top.layer.close(loading);
	}
	$.fn.imageUploadUtils.methods = {
		
	}
	$.fn.imageUploadUtils.defaults = {
		data		: "data",
		ext			: "ext",
		msg			: "msg",
		preview		: "uploadPreview"
	};
})(jQuery);